<template>
  <div class="check-details no-head">
    <div class="user-mess">
      <div class="cell-img">
        <div class="user"><img src="./../../assets/images/user2.png"/></div>
      </div>
      <div class="cell-text">
        <div class="user-name">
          <div class="name">{{ detailData.patientName }}</div>
          <!--          <div class="btnns">-->
          <!--            <el-button type="primary">编辑</el-button>-->
          <!--            <el-button>上一个</el-button>-->
          <!--            <el-button>下一个</el-button>-->
          <!--          </div>-->
        </div>
        <el-form ref="form" class="form">
          <el-row>
            <el-col :span="8">
              <el-form-item label="患者信息">
                病例号：{{ detailData.caseNumber }}
              </el-form-item>
              <div class="list"><span class="gray">患者年龄：</span>{{ detailData.age }}岁</div>
              <div class="list"><span class="gray">患者性别：</span>{{ detailData.gender == '2' ? '男' : '女' }}</div>
              <div class="list"><span class="gray">主治医师：</span>{{ detailData.attendingDoctor }}</div>
              <div class="list"><span class="gray">科室：</span>{{ detailData.deptName }}</div>
            </el-col>
            <el-col :span="8">
              <el-form-item label="样本信息">
                样本编号：{{ detailData.specimenNo }}
              </el-form-item>
              <div class="list"><span class="gray">标本种类：{{ detailData.type }}</span>血液</div>
              <div class="list"><span class="gray">试剂批号：</span></div>
              <div class="list"><span class="gray">送检医师：</span>{{ detailData.inspector }}</div>
              <div class="list"><span class="gray">检验项目：</span>{{ detailData.projectName }}</div>
              <div class="list"><span class="gray">送检时间：</span>{{ detailData.detectionTime }}</div>
            </el-col>
            <el-col :span="8">
              <el-form-item label="仪器信息">
                仪器编号：{{ detailData.instrumentNo }}
              </el-form-item>
              <div class="list"><span class="gray">设备名称：</span><span class="blue-primary">{{
                  detailData.instrumentName
                }}</span></div>
              <!--              <div class="list"><span class="gray">负责人：</span><span class="blue-primary">刘备</span></div>-->
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div><!------user-mess 用户信息------>
    <div class="gray-card">
      <div class="card-head">
        <div class="cell-title">检验结果</div>
        <div class="cell-btn">
          <!--          <el-button round>编辑</el-button>-->
          <el-button round @click.native="getTableList">刷新</el-button>
        </div>
      </div>
      <div class="card-body">
        <el-table height="500" :data="tableData" v-loading="loading" style="width: 100%">
          <el-table-column label="序号">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="itemEname" label="项目代码" :show-overflow-tooltip="true"/>
          <el-table-column prop="itemName" label="检验项目" :show-overflow-tooltip="true"/>
          <el-table-column prop="detectionValue" label="结果值" :show-overflow-tooltip="true"/>
          <el-table-column prop="referenceValue" label="参考区间" :show-overflow-tooltip="true"/>
          <el-table-column prop="unit" label="单位" :show-overflow-tooltip="true"/>
          <!--          <el-table-column prop="detection" label="检测方法" :show-overflow-tooltip="true"></el-table-column>-->
        </el-table>
      </div>
      <div class="card-foot">
        <div class="other-texts">
          <div class="list">检验编号：{{ detailData.detectionNo }}</div>
          <div class="list">采样时间：{{ detailData.samplingTime }}</div>
          <div class="list">检验时间：{{ detailData.patientTime }}</div>
          <div class="list">检验者：{{ detailData.inspector }}</div>
        </div><!--other-texts 信息列表-可单独使用--->
      </div>
    </div>

    <!--    <el-card class="box-card danger-card" v-if="detailData.result == '0'">-->
    <!--      <p class="wanr-title">危急值报警：<span class="red">RBP</span></p>-->
    <!--      <div class="other-texts inline-list">-->
    <!--        <div class="list">报告人：张欣慧</div>-->
    <!--        <div class="list"> 报告时间：2021/09/08 12:00</div>-->
    <!--      </div>-->
    <!--    </el-card>-->


    <div class="details-foot">
      <div class="cell-text">
        <div v-if="detailData.result == '0'">
          <p class="title">危急值报警：<span class="red">{{ this.crisisStr }}</span></p>
          <p class="text">检验项目中发现有危急值项，建议立即发起危急值处理流程</p>
        </div>
        <div v-if="detailData.result == '1'">
          <p class="title">检测结果：<span style="color: #33C596">正常</span></p>
          <p class="text">请检测者确认信息并提交检测结果</p>
        </div>
      </div>
      <div class="cell-btn">
        <el-button type="primary" v-if="(detailData.result == '1' && processFlage=='0')"
                   @click.native="handleConfirm(1)">结果确认
        </el-button>
        <el-button type="primary" v-if="(detailData.result == '1' && processFlage=='1')"
                   @click.native="handleConfirm(2)">审核确认
        </el-button>
        <el-button type="danger" v-if="detailData.result == '0' && processFlage=='0'"
                   @click.native="handleConfirm(3)">发送危急值处理申请
        </el-button>
        <el-button type="danger" v-if="detailData.result == '0' && processFlage=='1'"
                   @click.native="handleConfirm(4)">提交
        </el-button>
        <el-button @click.native="handleClose">取消</el-button>
      </div>
    </div>
    <el-card class="box-card gray-card" v-if="detailData.result == '0' && processFlage=='1'">
      <div slot="header" class="clearfix">
        <span>危急值处理</span>
      </div>
      <el-form ref="form" label-width="100px">
        <el-form-item label="原因分析：" :model="form">
          <el-input type="textarea" v-model="form.reson" style=" width:650px; height:100px;"/>
        </el-form-item>
        <el-form-item label="上一环节：">
          {{ this.processData[0].process }}
        </el-form-item>
        <el-form-item label="流转意见：">
          <el-input type="textarea" v-model="form.opinion" style=" width:650px; height:100px;"/>
        </el-form-item>
        <el-form-item label="下一步环节：">
          危急值处理人员-危急值处理
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {listDetectionItems} from "@/api/business/detectionItems"
import {listDetectionHandle, addDetectionHandle} from "@/api/business/detectionHandle"

export default {
  name: "checkDetail",
  data() {
    return {
      loading: false,
      tableData: [],
      processData: [],
      processFlage: '0',
      detailData: {},
      crisisStr: '',
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        detectionId: ''
      },
      processParams: {
        pageNum: 1,
        pageSize: 1000,
        detectionId: ''
      },
      form: {
        reson: '',
        opinion: ''
      }
    };
  },
  watch: {},
  created() {

  },
  methods: {
    // 结果确认 1: 正常确认，2：正常审核，3：危急值发送，4：危急值审核
    handleConfirm(type) {
      let str = type == 1 ? '结果确认' : type == 2 ? '结果审核' : type == 3 ? '危急值发送' : '危急值处理人员-危急值处理';
      let add = {
        detectionId: this.detailData.id,
        process: str,
        stauts: 1,
        receiveId: this.detailData.deptId,
        reson: this.form.reson,
        opinion: this.form.opinion
      }
      addDetectionHandle(add).then((res) => {
        this.$message.success('操作成功')
        this.handleClose()
      })
    },
    // 获取处理环节数据
    getProcessData() {
      listDetectionHandle(this.processParams).then((res) => {
        this.processData = res.rows
        if (res.total == 1) {
          this.processFlage = '1'
        } else if (res.total >= 2) {
          this.processFlage = '2'
        } else {
          this.processFlage = '0'
        }
      })
    },
    handleData(obj) {
      this.detailData = obj
      this.queryParams.detectionId = obj.id
      this.processParams.detectionId = obj.id
      this.$nextTick(() => {
        this.getTableList();
        this.getProcessData();
      })
    },
    getTableList() {
      this.tableData = []
      this.loading = true
      listDetectionItems(this.queryParams).then((res) => {
        this.loading = false
        this.tableData = res.rows
        if (res.total > 0) {
          let arr = res.rows.filter(x => (parseInt(x.detectionValue) < parseInt(x.referenceValue.split('-')[0])
            || parseInt(x.detectionValue) >= parseInt(x.referenceValue.split('-')[1])))
          if (arr) {
            let strArr = []
            arr.map(item => {
              strArr.push(item.itemEname)
            })
            this.crisisStr = strArr.join('，')
          }
        }
      })
        .catch((e) => {
          this.loading = false
        })
    },
    // 关闭详情页面
    handleClose() {
      this.detailData = {}
      this.processData = []
      this.tableData = []
      this.processFlage = '0'
      this.crisisStr = ''
      this.form = {}
      this.$emit('close', false)
    }
  }
};
</script>
